package com.iva.utils;

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import com.iva.model.TbPeriodoEvaluacion;
import com.iva.service.findService;

public class EscoolUtils {


	public DateFormat dateFormat = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy",Locale.US);
	public DateFormat dateFormatDT = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
	
	public String[] getFechasPeriodo(String fechaInicio, String fechaFin){
		Calendar calInicio = new GregorianCalendar();
		Calendar calFin = new GregorianCalendar();
		Calendar totalDays = Calendar.getInstance();
		ArrayList<String> fechas = null;
		String fechasReturn [] = null;
		int count = 0;
		DateFormatSymbols dfs = new DateFormatSymbols();
		String weekdays[] = dfs.getWeekdays();
		try{
			calInicio.setTime(this.dateFormat.parse(fechaInicio));
			calFin.setTime(this.dateFormat.parse(fechaFin));
			totalDays.setTimeInMillis(calFin.getTime().getTime() - calInicio.getTime().getTime());
			System.out.println("dif days " + totalDays.get(Calendar.DAY_OF_YEAR));
			 fechas = new ArrayList<String>(); 
			while(calInicio.getTime().before(calFin.getTime())){
				
				if(!(weekdays[calInicio.get(Calendar.DAY_OF_WEEK)].equals("Saturday") || weekdays[calInicio.get(Calendar.DAY_OF_WEEK)].equals("Sunday"))){
					System.out.println("Name of the Day "+dateFormat.format(calInicio.getTime()));
					fechas.add(dateFormatDT.format(calInicio.getTime())); 
					
				}
				calInicio.add(Calendar.DATE, 1);
				
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
		fechasReturn = new String[fechas.size()];
		for(String fc:fechas){
			fechasReturn[count] = fc;
			count++;
		}
		return fechasReturn;
	}
}



